home *** CD-ROM | disk | FTP | other *** search
- ===========================================================================
- BBS: The Abacus * HST/DS * Potterville MI
- Date: 03-29-93 (20:48) Number: 75
- From: MARK CORGAN Refer#: 189
- To: DALE DAVIS Recvd: NO
- Subj: Write Protected Disks Conf: (36) C Language
- ---------------------------------------------------------------------------
- Hello Dale!
-
- 25 Mar 93, Dale Davis writes to All:
-
- DD> Does anyone have any clues as to how I can check a disk to determine if it
- DD> is write protected before I write to it. I'm writing a DOS program, and
- DD> I've tried a couple different things, but I keep crashing the program and
- DD> getting the DOS write-proteced disk error. I know the answer is probobly
- DD> real obvious and located on page 1 of every C book I own, but if anyone
- DD> out there is really bored and can clue me in, I'd really appreciate it!
-
- Try out this code. It is for drive A: but you should be able to follow it enough
- to test for drive C:.
-
-
- #include <stdio.h>
- #include <dos.h>
- #include <stdlib.h>
-
- #define RETURN_OK 0
- #define RETURN_WRITE_PROTECT 1
- #define RETURN_OTHER 2
-
- char far buffer[10000];
- char far *pbuf = buffer;
-
- void main(void)
- {
- union REGS inregs, outregs;
- struct SREGS segregs;
- int retries = 0;
- int rc = RETURN_OK;
-
- // Read logical sector 1
- inregs.h.ah = 0x00; // Just clear it out
- inregs.h.al = 0x00; // Disk drive A:
- inregs.x.cx = 0x01; // Number of sectors to read
- inregs.x.dx = 0x01; // Logical sector 1 (FAT)
- inregs.x.bx = FP_OFF(pbuf); // Offset of buffer
- segregs.ds = FP_SEG(pbuf); // Segment address of buffer
- int86x(0x25, &inregs, &outregs, &segregs);
-
- // If the carry flag is set, then there was an error
- if (outregs.x.cflag) {
- rc = RETURN_OTHER;
- } else {
- // Write logical sector 1
- inregs.h.ah = 0x00; // Just clear it out
- inregs.h.al = 0x00; // Disk drive A:
- inregs.x.cx = 0x01; // Number of sectors to write
- inregs.x.dx = 0x01; // Logical sector 1 (FAT)
- inregs.x.bx = FP_OFF(pbuf); // Offset of buffer
- segregs.ds = FP_SEG(pbuf); // Segment address of buffer
- int86x(0x26, &inregs, &outregs, &segregs);
-
- // If the carry flag is set, then there was an error
- if (outregs.x.cflag) {
- // If ah = 3 then there was a write protect error
- if (outregs.h.ah == 3) {
- rc = RETURN_WRITE_PROTECT;
- } else {
- rc = RETURN_OTHER;
- }
- }
- }
- exit(rc);
- }
-
-
-
- Mark
-
- --- GoldED 2.40
- * Origin: -*- Sound and Image -*- (1:213/810)
- SEEN-BY: 1/211 11/2 4 13/13 101/1 108/89 109/25 110/69 114/5 123/19 124/1
- SEEN-BY: 153/752 154/40 77 157/2 159/100 125 575 950 203/23 209/209 280/1
- SEEN-BY: 390/1 396/1 5 15 730/6 2270/1 3603/20
-